package jTableTest;

import java.awt.Container;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.GroupLayout.Alignment;
import javax.swing.UIManager;
import javax.swing.WindowConstants;


import static javax.swing.GroupLayout.Alignment.*;

public class GroupLayoutDemo extends JFrame{
    
    public GroupLayoutDemo() {
        JLabel label = new JLabel("Find What:");;
        JTextField textField = new JTextField();
        textField.setText("Entertext");
        JCheckBox caseCheckBox = new JCheckBox("Match Case");
        JCheckBox wrapCheckBox = new JCheckBox("Wrap Around");
        JCheckBox wholeCheckBox = new JCheckBox("Whole Words");
        JCheckBox backCheckBox = new JCheckBox("Search Backwards");
        JButton findButton = new JButton("Find");
        JButton cancelButton = new JButton("Cancel");
        
        String[] columnNames = { "Terms", "Contents", "Tags", "Micellaneous" };
        Object[][] data = { { null, null, null, null } ,
                { null, null, null, null } ,
                { null, null, null, null } ,
                { null, null, null, null } };
        JTable table = new JTable(data, columnNames);
         
        
        
        caseCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        wrapCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        wholeCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        backCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        
        
        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setAutoCreateGaps(true);
        layout.setAutoCreateContainerGaps(true);
        
        layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING)
                .addComponent(table)
                .addGroup(layout.createSequentialGroup()
                .addComponent(label)
                .addGroup(layout.createParallelGroup(LEADING)
                        .addComponent(textField)
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(LEADING)
                                        .addComponent(caseCheckBox)
                                        .addComponent(wholeCheckBox))
                                .addGroup(layout.createParallelGroup(LEADING)
                                       .addComponent(wrapCheckBox)
                                       .addComponent(backCheckBox))))
                 .addGroup(layout.createParallelGroup(Alignment.LEADING)
                         .addComponent(findButton)
                         .addComponent(cancelButton))));
        

        // set findButton and cacelButton having the same size
        layout.linkSize(SwingConstants.HORIZONTAL, findButton, cancelButton);
        

        layout.setVerticalGroup(layout.createSequentialGroup()
             .addComponent(table)
            .addGroup(layout.createParallelGroup(BASELINE)
                .addComponent(label)
                .addComponent(textField)
                .addComponent(findButton))
            .addGroup(layout.createParallelGroup(LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(BASELINE)
                        .addComponent(caseCheckBox)
                        .addComponent(wrapCheckBox))
                    .addGroup(layout.createParallelGroup(BASELINE)
                        .addComponent(wholeCheckBox)
                        .addComponent(backCheckBox)))
                .addComponent(cancelButton))
        );
        setTitle("Find");
        pack();
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        
        
    }
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    UIManager.setLookAndFeel(
                                  "javax.swing.plaf.metal.MetalLookAndFeel");
                                //  "com.sun.java.swing.plaf.motif.MotifLookAndFeel");
                                //UIManager.getCrossPlatformLookAndFeelClassName());
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                new GroupLayoutDemo().setVisible(true);
            }
        });
    }

}
